﻿using System;
using System.Windows.Data;
using System.Windows.Media;

namespace CannedHeater.View.Converters
{
    /// <summary>
    /// Converts a boolean ("is_valid") into a corresponding (error, valid) brush.
    /// </summary>
    public class BoolValidIndicatorToBrushConverter : IValueConverter
    {
        /// <summary>
        /// Brush to use for non_valid (bool == false)
        /// </summary>
        private Brush ErrorBrush = new SolidColorBrush(Colors.Red);

        /// <summary>
        /// Converts a boolean ("is_valid") into a corresponding brush.
        /// </summary>
        /// <param name="value">Boolean</param>
        /// <param name="targetType">Unused</param>
        /// <param name="parameter">Default brush (used for is_valid (value = true))</param>
        /// <param name="culture">Unused</param>
        /// <returns>
        /// Default brush (<see cref="parameter"/>) if <see cref="value"/> is true
        /// Otherwise returns error brush (color red)
        /// </returns>
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null || parameter == null) return null;

             Brush ValidBrush = (Brush)parameter;

            bool b = (bool)value;
            return b ? ValidBrush : ErrorBrush;

        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return null; // Not needed
        }
    }
}
